package org.aphelie.torg.ruler.internal.ui.editor;

import org.aphelie.torg.ruler.internal.ui.TGRFormEditor;
import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IStatusLineManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.ui.actions.ActionContext;
import org.eclipse.ui.views.contentoutline.ContentOutlinePage;

public abstract class TGROutlinePage extends ContentOutlinePage {

	protected TGRFormEditor fEditor;

	public TGROutlinePage(TGRFormEditor editor) {
		fEditor = editor;
	}

	public TGROutlinePage() {
	}

	public void makeContributions(IMenuManager menuManager, IToolBarManager toolBarManager, IStatusLineManager statusLineManager) {

		MenuManager popupMenuManager = new MenuManager();
		IMenuListener listener = new IMenuListener() {
			public void menuAboutToShow(IMenuManager manager) {
				ISelection selection = getSelection();
				/* TODO
				PluginSearchActionGroup actionGroup = new PluginSearchActionGroup();
				if (fEditor != null)
					actionGroup.setBaseModel(fEditor.getAggregateModel());
				actionGroup.setContext(new ActionContext(selection));
				actionGroup.fillContextMenu(manager);
				*/
			}
		};

		popupMenuManager.addMenuListener(listener);
		popupMenuManager.setRemoveAllWhenShown(true);
		Control control = getTreeViewer().getControl();
		Menu menu = popupMenuManager.createContextMenu(control);
		control.setMenu(menu);
	}
	
}
